<template>
  <div>
    <div class="imgWrite-top">
      <h4 style="text-align: left; color: #126bff">图文上报管理</h4>
      <!--         :rules="rules" -->
      <el-form
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="115px"
        style="
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
          box-sizing: border-box;
          line-height: 40px;
          height: auto;
        "
      >
        <el-form-item
          label="所属行政区域 ："
          prop="xzqydm"
          style="width: 310px"
        >
          <el-select v-model="formData.xzqydm" placeholder="请选择行政区域">
            <el-option
              v-for="item in xzqydm"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属派出所 ：" prop="ssjwsq" style="width: 300px">
          <el-input
            v-model="formData.ssjwsq"
            placeholder="请输入所属派出所"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="护卫学校 ：" prop="dwmc" style="width: 300px">
          <el-input
            v-model="formData.dwmc"
            placeholder="请输入护卫学校"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>

        <el-form-item label="上报人姓名 ：" prop="xm" style="width: 300px">
          <el-input
            v-model="formData.xm"
            placeholder="请输入姓名"
            clearable
            :style="{ width: '100%' }"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="上报时段 ：" prop="time">
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '100%' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="small" style="float: right">
          <el-button
            @click="resetForm()"
            style="background-color: #e6effa; color: #126bff"
            >重置</el-button
          >
          <el-button
            type="primary"
            @click="submitForm(formData)"
            style="color: #ffffff; background-color: #126bff"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="warn-content" style="width: 100%">
      <el-table
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        style="width: 100%"
      >
        <el-table-column prop="id" label="序号" width="100">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <el-table-column prop="dwmc" label="护卫学校名称"> </el-table-column>
        <el-table-column prop="ssjwsq" label="所属派出所"> </el-table-column>
        <el-table-column prop="xm" label="上报人姓名"> </el-table-column>
        <el-table-column prop="xlmj_lxdh" label="上报人手机号">
        </el-table-column>
        <el-table-column prop="title" label="标题"> </el-table-column>
        <el-table-column prop="content" label="正文内容" width="300">
          <template v-slot="scope">
            <span class="rowText">{{ scope.row.content }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="imgSrc" label="照片" width="200">
          <template v-slot="scope">
            <!-- <div
              style="display: inline"
              v-for="(item, index) in scope.row.imgSrc"
              :key="index"
            > -->
            <img
              v-if="scope.row.img_one"
              style="width: 40px; height: 40px"
              :src="scope.row.img_one"
              alt=""
            />
            <img
              v-if="scope.row.img_two"
              style="width: 40px; height: 40px"
              :src="scope.row.img_one"
              alt=""
            />
            <img
              v-if="scope.row.img_three"
              style="width: 40px; height: 40px"
              :src="scope.row.img_one"
              alt=""
            />
            <!-- </div> -->
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="上报时间" width="160">
          <!-- moment(data * 1000).format('YYYY-MM-DD') -->
          <!-- <template v-slot="scope">
            {{ scope.update_time }}
          </template> -->
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[8, 20, 40, 80]"
        :page-size="pageSize"
        layout="total, prev, pager, next, sizes"
        :total="tableData.length"
        style="float: right; margin-top: 20px"
      >
      </el-pagination>
    </div>
    <div>
      <el-dialog
        title="详情"
        :visible.sync="dialogVisible"
        width="550px"
        :before-close="handleClose"
        style="border-radius: 20px"
      >
        <div style="display: flex; flex-wrap: wrap; text-align: left">
          <div class="upIpfo">
            <p>护卫学校名称：{{ detaile.dwmc }}</p>
            <p>所属派出所：{{ detaile.ssjwsq }}</p>
          </div>
          <div class="upIpfo">
            <p>上报人姓名：{{ detaile.xm }}</p>
            <p>上报人手机号：{{ detaile.xlmj_lxdh }}</p>
          </div>
          <div class="upIpfo">
            <p>标题：{{ detaile.title }}</p>
            <p class="text">正文内容：{{ detaile.content }}</p>
          </div>
          <div class="upIpfo">
            <p style="">
              照片：
              <img
                v-if="detaile.img_one"
                style="width: 50px; height: 50px; vertical-align: text-top"
                :src="detaile.img_one"
                alt=""
              />
              <img
                v-if="detaile.img_two"
                style="width: 50px; height: 50px; vertical-align: text-top"
                :src="detaile.img_two"
                alt=""
              />
              <img
                v-if="detaile.img_three"
                style="width: 50px; height: 50px; vertical-align: text-top"
                :src="detaile.img_three"
                alt=""
              />
            </p>
            <p>上报时间：{{ detaile.create_time }}</p>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { imageTextLog } from "@/api/police";
import { Loading } from "element-ui";
export default {
  name: "WARN",
  components: {},
  data() {
    return {
      currentPage4: 4,
      // 按页数查询数据
      currentPage: 1,
      pageSize: 8,
      // 行政区域代码
      xzqydm: [
        {
          text: "安次区",
          value: "安次区",
        },
        {
          text: "广阳区",
          value: "广阳区",
        },
        {
          text: "经济开发区",
          value: "经济开发区",
        },
        {
          text: "永清县",
          value: "永清县",
        },
        {
          text: "香河县",
          value: "香河县",
        },
      ],
      // 条件搜索表单数据
      formData: {
        xzqydm: "", //所属行政区域
        ssjwsq: "", //所属派出所
        dwmc: "", // 单位名称
        xm: "", // 上报人姓名
        time: "",
      },
      // 条件搜索使用数据
      searchData: {
        xzqydm: "", //所属行政区域
        ssjwsq: "", //所属派出所
        dwmc: "", // 单位名称
        xm: "", // 上报人姓名
        begin_time: "", // 开始时间
        end_time: "", // 结束时间
        page: "1",
        pagesize: "1000",
      },
      detaile: {},
      tableData: [],
      dialogVisible: false,
    };
  },
  watch: {
    $route(to, from) {
      console.log(to, from);
    },
  },
  created() {},
  mounted() {
    this.initdata();
  },

  methods: {
    // 数据初始化
    initdata() {
      // let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      imageTextLog(this.searchData).then((res) => {
        console.log(res);
        this.currentPage = 1;
        loadingInstance.close();
        this.tableData = res.data;
      });
    },
    // 没用上
    timestampToTime2(timestamp) {
      console.log(timestamp);
      if (timestamp === 0 || timestamp == null) {
        return "";
      } else {
        var date = new Date(timestamp * 1000);
        var Y = date.getFullYear() + "-";
        var M =
          (date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1) + "-";
        var D =
          date.getDate() < 10
            ? "0" + date.getDate() + " "
            : date.getDate() + " ";
        var H = date.getHours() + ":";
        var M2 =
          (date.getMinutes() < 10
            ? "0" + date.getMinutes()
            : date.getMinutes()) + ":";
        var S =
          date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        let time = Y + M + D + H + M2 + S;
        console.log(time);
        return Y + M + D + H + M2 + S;
      }
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    // 条件查询
    submitForm(formData) {
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
      });
      this.searchData.xzqydm = formData.xzqydm;
      this.searchData.ssjwsq = formData.ssjwsq;
      this.searchData.dwmc = formData.dwmc;
      this.searchData.xm = formData.xm;
      if (formData.time == [] || formData.time == null) {
        this.searchData.end_time = "";
        this.searchData.begin_time = "";
      } else {
        this.searchData.end_time = formData.time[1];
        this.searchData.begin_time = formData.time[0];
      }
      console.log(this.searchData);
      imageTextLog(this.searchData).then((res) => {
        console.log(res);
        this.currentPage = 1;
        that.$nextTick(() => {
          that.tableData = res.data;
          // 以服务的方式调用的 Loading 需要异步关闭
          loadingInstance.close();
        });
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
      this.initdata();
    },
    handleClick(row) {
      console.log(row);
      this.dialogVisible = true;
      this.detaile = row;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },
};
</script>
<style scoped lang="scss" >
.imgWrite-top {
  //
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.imgWrite-top {
  width: calc(100%);
}

// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
/deep/.el-form-item {
  height: 50px;
}

/deep/.el-form-item__label {
  width: 104px !important;
  padding: 0 !important;
}
.warn-content {
  margin-top: 20px;
  //
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.el-table .el-table__cell {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
}
.upIpfo {
  display: flex;
  width: 100%;
  //
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  //
  display: inline-block;
  // background-color: skyblue;
}
/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }
/deep/.el-dialog {
  border-radius: 15px !important;
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 0 20px 20px 20px !important;
}
// /deep/.el-dialog__body tbody > .el-table__row {
//   color: red !important;
//   /deep/.el-table_1_column_5 {
//     color: red !important;
//   }
// }
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
}
// el-table_1_column_5   el-table__cell
.rowText {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
/deep/.el-range-editor.el-input__inner {
  // border: 1px red solid !important;
  width: 66% !important;
}
</style>
